<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html >
<html>
<head>
<%@ include file="/WEB-INF/view/include/jQgrid.jsp"%>

</head>
<body style="background-color: white;" class="gray-bg">
                    <div class="ibox-content">
                        <form  class="form-horizontal m-t" id="signupForm">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">用户名：</label>
                                <div class="col-sm-8">
                                    <input id="username" name="username" value="${users.username }" class="form-control" type="text">
                                    <input name = "id" type="hidden" value="${users.id }">
                                    <span class="help-block m-b-none"><i class="glyphicon glyphicon-info-sign"></i> 这里写点提示的内容</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">姓名：</label>
                                <div class="col-sm-8">
                                    <input id="truename" name="truename" value="${users.truename }" class="form-control" type="text" aria-required="true" aria-invalid="false" class="valid">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">电话号码：</label>
                                <div class="col-sm-8">
                                    <input id="mobile" name="mobile" value="${users.mobile }" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">
                                </div>
                            </div>
                    <!--         <div class="form-group">
                                <label class="col-sm-3 control-label">密码：</label>
                                <div class="col-sm-8">
                                    <input id="password" name="password" class="form-control" type="password">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">确认密码：</label>
                                <div class="col-sm-8">
                                    <input id="confirm_password" name="confirm_password" class="form-control" type="password">
                                    <span class="help-block m-b-none"><i class="glyphicon glyphicon-info-sign"></i> 请再次输入您的密码</span>
                                </div>
                            </div> -->
                            <div class="form-group">
                                <label class="col-sm-3 control-label">邮箱：</label>
                                <div class="col-sm-8">
                                    <input id="email" name="email" value="${users.email }" class="form-control" type="email">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">所属部门：</label>
                                <div class="col-sm-8">
                                	<c:if test="${depid!=-1 }">
                                   	<select name="depid"  class="form-control" disabled="disabled">
                                   			<option value="${depb.depId }" selected=selected >${depb.depName }</option>
                                   	</select>
                                   		<input name="depid" value="${depb.depId }" type="hidden">
                                   	</c:if>
                                   	<c:if test="${depid==-1 }">
                                   	<select name="depid"  class="form-control">
                                   		<c:forEach var="dep" items="${dep }" >
                                   			<option value="${dep.depId }" <c:if test="${users.depid==dep.depId }">selected=selected</c:if> <c:if test="${dep.companyId==0 }"> disabled="disabled"</c:if> >${dep.depName }</option>
                                   		</c:forEach>
                                   	</select>
                                   	</c:if>
                                </div>
                            </div>
                            <div class="form-group">
                            <label class="col-sm-3 control-label">拥有角色：</label>
                             <div class="col-sm-8" id="roless">
                                <select id="roleIds" name="roleIds" data-placeholder="选择角色" class="chosen-select" multiple style="width:100%;" tabindex="4">
                                 	<c:forEach var="role" items="${rolecake }">
                                  		 <option value="${role.role.id }" <c:if test="${role.selected=='selected' }">selected</c:if> >${role.role.name }</option>
                                  	</c:forEach>
                                </select>
                             </div>
                            </div>
                            <div class="form-group">
                            <label class="col-sm-3 control-label">数据权限：</label>
                             <div class="col-sm-8">
                                <input type="radio" name="datarole" value="0" <c:if test="${users.datarole eq 0}">checked</c:if> />全部
                                <input type="radio" name="datarole" value="1" <c:if test="${users.datarole eq 1}">checked</c:if>/>公司
                                <input type="radio" name="datarole" value="2" <c:if test="${users.datarole eq 3}">checked</c:if>/>个人
                             </div>
                            </div>
                            <div class="form-group" id="addimg">
                                <label class="col-sm-3 control-label">添加图片：</label>
                                <div class="col-sm-8">
                                    <input type="file" name="file" style="display: none;" id="addimgs" onchange="getFileSize(event);" accept="image/*" />
                                    <span style='width: 78px; height: 78px; display: none; cursor: pointer; ' id="imglist"  onclick="$('#addimgs').click();"><img src=''  width='78px' height='78px' id="imgshow"></span>
                                    <span class="picUploadBtn" onclick="$('#addimgs').click();" id="imglist1p" style="border: 1px solid #999999; width: 78px; height: 78px; display: block; cursor: pointer;background-image: url('<%=contextPath%>/static/img/uploadimg.png');"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-3">
                                    <button class="btn btn-primary" type="button" id="sub">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
	
	
	<script>
	$(function(){
	    $('#roleIds').chosen();
	    $("#sub").click(function(){
			var username = $("#username").val();
			var id = ${users.id };
			if(username.length==0){
				$("#username").tips({
					side:3,
		            msg:'用户名不能为空！',
		            bg:'#AE81FF',
		            time:1
		        });
				$("#username").focus();
				return;
			}else{
				 $.ajax({
					 url:"<%=contextPath %>/user/getbyname?name="+username+"&id="+id,
					 dataType:'json',
					 success:function(data){
						if(!data){
							$("#username").tips({
								side:3,
					            msg:'用户已存在',
					            bg:'#AE81FF',
					            time:1
					        });
							$("#username").focus();
							return;
						}
					 }
				 });
			}
			
			if($("#truename").val().length==0){
				$("#truename").tips({
					side:3,
		            msg:'姓名不能为空！',
		            bg:'#AE81FF',
		            time:1
		        });
				$("#truename").focus();
				return;
			}
			if(!mobile($("#mobile").val(),"#mobile")){
				return;	
			}
		
			if(!email($("#email").val(),"#email")){
				return;	
			}
			
			if($("#roleIds").val()==null){
				$("#roless").tips({
					side:3,
					msg:'请选中角色',
					bg:'#AE81FF',
					time:1
				});
				$("#roleIds").focus();
				return;
			}
			$("#signupForm").ajaxSubmit({
	        	url:'<%=contextPath %>/user/edit',
	        	type:'post',
	        	dataType:"json",
	        	success:function(data){
	        		if(data.code==200){
	        			swal({
	        			    title: data.message,
	        			    type: "success",
	        			    showCancelButton: false,
	        			    confirmButtonText: "确定",
	        			    animation:"slide-from-bottom",
	        			    closeOnConfirm: true
	        			},function(){
	        				top.Dialog.close();
	        			});
	        		}else{
	        			swal("错误", data.message, "error");
	        		}
	        	}
	      }); 
			
		});
	});
    function getFileSize(evt) {
        var files = evt.target.files;
        var thesrc = window.URL.createObjectURL(files[0]);
        $("#imglist1p").hide();
        $("#imglist").show();
        $("#imgshow").attr("src", thesrc);
    }
	</script>
</body>
</html>